package com.example.composableexample.snackbar

import androidx.compose.material.Scaffold
import androidx.compose.material.ScaffoldState
import androidx.compose.material.Snackbar
import androidx.compose.material.rememberScaffoldState
import androidx.compose.material3.Button
import androidx.compose.material.SnackbarHost
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.tooling.preview.Preview
import javax.inject.Inject

@Preview
@Composable
fun SnackBarDemoScreenSimple() {
    val scaffoldState: ScaffoldState = rememberScaffoldState()

    val snackBarDelegate = SnackBarDelegate().apply {
        snackBarHostState = scaffoldState.snackbarHostState
        coroutineScope = rememberCoroutineScope()
    }
    Scaffold(
        scaffoldState = scaffoldState,
        snackbarHost = { it ->
            SnackbarHost(hostState = it) {
                val backgroundColor = snackBarDelegate.snackBarBackgroundColor
                Snackbar(snackbarData = it, backgroundColor = backgroundColor)
            }
        }
    ) {
        Button(onClick = { snackBarDelegate.showSnackBar(SnackBarState.ERROR, "登录失败") }) {
            Text(text = "Click")
        }
    }
}